import 'package:app_admin/extension/custom_ext.dart';
import 'package:app_admin/pages/select/select_logic.dart';
import 'package:app_admin/res/styles.dart';
import 'package:app_admin/widgets/button.dart';
import 'package:app_admin/widgets/chat_radio.dart';
import 'package:app_admin/widgets/title_bar.dart';
import 'package:app_admin/widgets/views.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:sprintf/sprintf.dart';

class SelectPage extends StatelessWidget {
  final logic = Get.find<SelectLogic>();

  SelectPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Obx(() => Scaffold(
          appBar: TitleBar.back(
            title: logic.isEdiotr ? "更新" : "选择",
            backgroundColor: Styles.c_0089FF,
          ),
          backgroundColor: Styles.c_F8F9FA,
          body: Column(
              // mainAxisSize: MainAxisSize.max,
              // mainAxisAlignment: MainAxisAlignment.start,
              // crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                // Container(
                Flexible(
                  child: SmartRefresher(
                      controller: logic.controller,
                      enablePullUp: false,
                      enablePullDown: true,
                      footer: IMViews.buildFooter(),
                      onRefresh: logic.load,
                      child: ListView.builder(
                          itemCount: logic.datas.length,
                          itemBuilder: (_, index) =>
                              Obx(() => _buildItemView(logic.datas[index])))),
                ),
                Container(
                  height: 66.h,
                  decoration: BoxDecoration(color: Styles.c_FFFFFF, boxShadow: [
                    BoxShadow(
                      offset: Offset(0, -1.h),
                      blurRadius: 4.r,
                      spreadRadius: 1.r,
                      color: Styles.c_000000_opacity4,
                    ),
                  ]),
                  padding: EdgeInsets.symmetric(horizontal: 16.w),
                  child: Obx(() => Row(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          Button(
                            height: 40.h,
                            //enabled: logic.enabledConfirmButton,
                            padding: EdgeInsets.symmetric(horizontal: 14.w),
                            text: sprintf("确定", [
                              logic.checkedList.length,
                              '999',
                            ]),
                            textStyle: Styles.ts_FFFFFF_14sp,
                            onTap: logic.confirmSelectedList,
                          ),
                        ],
                      )),
                )
              ]),
        ));
  }

  Widget _buildItemView(String str) => GestureDetector(
        behavior: HitTestBehavior.translucent,
        onTap: () => {logic.select(str)},
        child: Container(
          padding: EdgeInsets.symmetric(horizontal: 16.w),
          height: 40.h,
          child: Row(
            children: [
              Padding(
                padding: EdgeInsets.only(right: 10.w),
                child: ChatRadio(
                  checked: logic.isChecked(str),
                  enabled: logic.isDefault(str),
                ),
              ),
              10.horizontalSpace,
              str.toText..style = Styles.ts_0C1C33_17sp,
            ],
          ),
        ),
      );
}
